package com.atguigu.gulimall.search.controller;

import com.atguigu.gulimall.search.service.SearchService;
import com.atguigu.gulimall.search.vo.SearchParam;
import com.atguigu.gulimall.search.vo.SearchResVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import javax.servlet.http.HttpServletRequest;

@Controller
public class SearchController {

    @Autowired
    private SearchService searchService;

    /***
     * 根据页面传递过来的页面查询参数,去ES中检索商品
     * @param param : 将页面提交的请求参数自动封装成指定对象
     * @param model : 用于保存查询结果对象
     * @return
     * HttpServletRequest的getQueryString()方法可以获取url的请求参数
     */
    @GetMapping("/list.html")
    public String listPage(SearchParam param , Model model, HttpServletRequest request){
        param.set_queryString(request.getQueryString());
        System.out.println("执行到这里了,param是  " + param);
        SearchResVo searchResVo = searchService.search(param);
        model.addAttribute("result",searchResVo);
        return "list";
    }
}
